{% extends '__base__.html' %}

{% block title %}协议分析配置-远程设备配置{% endblock %}

{% block beforehead %}

<script>
function initVM(data) {
    $('#div-remotes').show();

    var vm = new Vue({
        el: '#div-remotes',
        data: {
            xyfx_remotes: data.xyfx_remotes
        },
        methods: {
            edit_config: function (config) {
                showConfirm('确认编辑？', '确认要编辑“' + config.name + '”？', function () {
                    postApi('/api/configs/' + config.id + '/edit', {}, function (err, r) {
                        if (err) {
                            return showError(err);
                        }
                        location.reload();
                    });
                });
            },
            delete_config: function (config) {
                showConfirm('确认删除？', '确认要删除评论“' + config.name + '”？删除后不可恢复！', function () {
                    postApi('/api/configs/' + config.id + '/delete', {}, function (err, r) {
                        if (err) {
                            return showError(err);
                        }
                        location.reload();
                    });
                });
            }
        }
    });
};
$(function() {
    getApi('/api/xyfx/remote', function (err, results) {
        if (err) {
            return showError(err);
        }
        initVM(results);
        $('#div-loading').hide();
       
    });
});
$(function() {
    var v = new Vue({
        el: '#form-add-remote-config',
        data: {
            serverip: '',
            username: '',
            password: '',
            port: ''
        },
        methods: {
            submit: function (event) {
                event.preventDefault();
                showError();
                postApi('/api/xyfx/add_remote_config', {
                    serverip: this.serverip,
                    username: this.username,
                    password: this.password,
                    port: this.port
                }, function (err, result) {
                    if (err) {
                        showError(err);
                    }
                    else {
                        return location.assign('/xyfx/remote');
                    }
                    stopLoading();
                });
            }
        }
    });
})
</script>

{% endblock %}

{% block content %}
    
    <div class="uk-width-1-1 uk-margin-bottom" >
        <div class="uk-panel uk-panel-box">
            <ul class="uk-breadcrumb">
            {% for m in menus %}
                {% if m.level == 2 and m.display == 1%}
                <li><a href="{{ m.url }}"><span>{{ m.name }}</span></a></li>
                {% endif %}
            {% endfor %}
            </ul>
        </div>
    </div>
    <div class="data-uk-margin">
        <button class="uk-button uk-button-primary" data-uk-modal="{target:'#model_add_remote',bgclose:false}"  type="button"> 新建 </button>
        <button class="uk-button uk-button-primary " type="button" disabled>删除</button>
    </div>

    <div id="model_add_remote" class="uk-modal " aria-hidden="true" style="display: none; overflow-y: scroll;">
        <div class="uk-modal-dialog  ">
            <button type="button" class="uk-modal-close uk-close"></button>
            <div class="uk-vertical-align-middle" style="width: 450px">
            <p><a href="/" class="uk-icon-button"><i class="uk-icon-html5"></i></a> 新建远程服务器配置</p>

            <form id="form-add-remote-config" v-on:submit="submit" class="uk-panel uk-panel-box uk-form">
                <div class="uk-alert uk-alert-danger uk-hidden"></div>
                <div class="uk-form-row">
                    <div class="uk-form-icon uk-width-1-1">
                        <i class="uk-icon-home"></i>
                        <input v-model="serverip" name="serverip" type="text" placeholder='服务器IP'maxlength="50" class="uk-width-1-1 uk-form-large">
                    </div>
                </div>
                <div class="uk-form-row">
                    <div class="uk-form-icon uk-width-1-1">
                        <i class="uk-icon-user"></i>
                        <input v-model="username" name="username" type="text" placeholder="用户名" maxlength="50" class="uk-width-1-1 uk-form-large">
                    </div>
                </div>
                <div class="uk-form-row">
                    <div class="uk-form-icon uk-width-1-1">
                        <i class="uk-icon-lock"></i>
                        <input v-model="password" name="password" type="password" placeholder="口令" maxlength="50" class="uk-width-1-1 uk-form-large">
                    </div>
                </div>
                <div class="uk-form-row">
                    <div class="uk-form-icon uk-width-1-1">
                        <i class="uk-icon-cog"></i>
                        <input v-model="port" name="port" type="text" placeholder="端口" maxlength="50" class="uk-width-1-1 uk-form-large">
                    </div>
                </div>
                <div class="uk-form-row">
                    <button type="submit" class="uk-width-1-1 uk-button uk-button-primary"><i class="uk-icon-sign-in"></i> 保存&激活</button>
                </div>
                
            </form>
            </div>
            
        </div>
    </div>

    <div id="div-remotes" class="uk-width-1-1" style="display:none">
        <table class="uk-table uk-table-hover">
            <thead>
                <tr>
                    <th class="uk-width-1-6">序号</th>
                    <th class="uk-width-1-6">服务器IP</th>
                    <th class="uk-width-2-6">服务器端口</th>
                    <th class="uk-width-1-6">用户名</th>
                    <th class="uk-width-1-6">操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="xr in xyfx_remotes" >
                    <td>
                        <span v-text="xr.id"></span>
                    </td>
                    <td>
                        <span v-text="xr.serverip"></span>
                    </td>
                    <td>
                        <span v-text="xr.port"></span>
                    </td>
                    <td>
                        <span v-text="xr.username"></span>
                    </td>
                    <td>
                        <a href="#0" v-on:click="edit_config(xc)"><i class="uk-icon-cog"></i>
                        <a href="#0" v-on:click="delete_config(xc)"><i class="uk-icon-trash-o"></i>
                    </td>
                </tr>
            </tbody>
        </table>
       
    </div>
    <div id="div-loading" class="uk-width-1-1 uk-text-center">
        <span><i class="uk-icon-spinner uk-icon-medium uk-icon-spin"></i> 正在加载...</span>
    </div>
{% endblock %}
